#include "common.fxh"

struct VertexInput
{
	float4 position		: POSITION0;
	float2 texCoord		: TEXCOORD0;
    float3 normal		: NORMAL0;
    float3 binormal     : BINORMAL0;
    float3 tangent		: TANGENT0;
};


struct VertexOutput
{
	float4 Position			: POSITION0;
	float2 texCoord			: TEXCOORD0;
	float4 NormalDepth			: TEXCOORD1;
};

VertexOutput VertexShader( VertexInput input )
{
	VertexOutput output;

	output.texCoord	= input.texCoord;


	output.Position	= mul(input.position,WorldViewProjection);

	output.NormalDepth.xyz	= mul(input.normal,WorldView);
	output.NormalDepth.w	= mul(input.position,WorldView).z;

	return output;
}


PixelShaderOutput PixelShader( VertexOutput input,float face : VFACE)
{
	float2 texCoord = input.texCoord * textureTiling;

	PixelShaderOutput output;

	output.Color	= tex2D(DiffuseTextureSampler,texCoord);
	clip(output.Color.a - 0.8);
	output.Color.a	= 1;

	output.Normal.xyz	= face * normalize(input.NormalDepth.xyz);
//	output.Normal.xy	= float2(dot(normalFromMap,float3(1,0,0)),dot(float3(0,1,0),normalFromMap));
	output.Normal.xyz	= 0.5f * (output.Normal.xyz + 1.0f);

	output.Normal.w	= tex2D(SpecularTextureSampler,texCoord).r;

	output.Depth	= input.NormalDepth.w;
	output.Back	= 1;
	return output;
}


technique Full
{
    pass GO
    {
        CullMode = None;//CCW
        VertexShader = compile vs_3_0 VertexShader();
        PixelShader = compile ps_3_0 PixelShader();
    }
}
